﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    /// <summary>
    /// group 8颗粒物干沉积参数
    ///  颗粒物的几何直径、沉降速率和标准偏差等。
    ///  CALPUFF GUI中包含了常用污染物的颗粒物沉积参数，，需提供这些参数作为默认
    /// </summary>
    public class PG8:Group
    {

        public PG8()
        {

            SizeParam.Add(new SizeDryParticles("SO2", 0, 0));
            SizeParam.Add(new SizeDryParticles("NOX", 0, 0));
            SizeParam.Add(new SizeDryParticles("HNO3", 0, 0));
            SizeParam.Add(new SizeDryParticles("NO", 0, 0));
            SizeParam.Add(new SizeDryParticles("NO2", 0, 0));
            SizeParam.Add(new SizeDryParticles("ODOR", 0, 0));
            SizeParam.Add(new SizeDryParticles("TOLUENE", 0, 0));
            SizeParam.Add(new SizeDryParticles("XYLENE", 0, 0));
            SizeParam.Add(new SizeDryParticles("B-PINENE", 0, 0));
            SizeParam.Add(new SizeDryParticles("A-PINENE", 0, 0));
            SizeParam.Add(new SizeDryParticles("SO4", .48, 2));
            SizeParam.Add(new SizeDryParticles("NO3", .48, 2));
            SizeParam.Add(new SizeDryParticles("PM10", .48, 2));
            SizeParam.Add(new SizeDryParticles("SOA", .48, 2));
            SizeParam.Add(new SizeDryParticles("H2O", .001, 0));
            SizeParam.Add(new SizeDryParticles("TXS", .001, 0));
            SizeParam[0].CalculateSpecies = true;

 
        }


        /// <summary>
        /// 颗粒物参数，阻力沉积模型计算颗粒物干沉积速率的参数
        /// </summary>
        List<SizeDryParticles> m_SizeParam = new List<SizeDryParticles>();
        /// <summary>
        /// 颗粒物参数，阻力沉积模型计算颗粒物干沉积速率的参数
        /// </summary>
        public List<SizeDryParticles> SizeParam
        {
            get { return m_SizeParam; }
            set { m_SizeParam = value; }
        }
        public override string WriteToGroup()
        {
            string Subgroup = "", TempStr;

            TempStr = StrWriter.GetCLine();
            TempStr += "INPUT GROUP: 8 -- Size parameters for dry deposition of particles" + "\r\n";
            Subgroup += TempStr;

            TempStr = StrWriter.GetCLine();
            Subgroup += TempStr;

            //进行排序
            List<string> arry = Sort.GetPollutantRightOrder();
            List<SizeDryParticles> arrySizeDryParticles = new List<SizeDryParticles>();
            arrySizeDryParticles.Clear();
            foreach (string a in arry)
            {
                for (int i = 0; i < SizeParam.Count; i++)
                {
                    if (a == SizeParam[i].SPECNAM)
                    {
                        arrySizeDryParticles.Add(SizeParam[i]);
                    }
                }
            }
            //---------------------------------------
            if (arrySizeDryParticles.Count > 0)
            {
                for (int i = 0; i < arrySizeDryParticles.Count; i++)
                {
                    if (arrySizeDryParticles[i].CalculateSpecies)
                    {
                        if (arrySizeDryParticles[i].IsDryParticles)
                        {
                            TempStr = "!       " + arrySizeDryParticles[i].SPECNAM + "   =   " + arrySizeDryParticles[i].DIAMETER.ToString() + ",   " + arrySizeDryParticles[i].DEVIATION.ToString() + "   !" + "\r\n";
                            Subgroup += TempStr;
                        }
                    }
                }
            }
            Subgroup += "! END !" + "\r\n";

            return Subgroup;
        }

        public override void ReadFromGroup(Dictionary<string, string> dic)
        {
            foreach (KeyValuePair<string, string> m_dic in dic)
            {

                SizeDryParticles sd = new SizeDryParticles("XX", 1, 1);

                this.SizeParam.Add(sd.ReadFromGroup(m_dic.Key, m_dic.Value));


            }

        }


    }



    /// <summary>
    /// 阻力沉积模型计算颗粒物干沉积速率的参数
    /// ：geometric mass mean diameter (microns) 和geometric standard deviation (microns)
    /// Group 3 中 标示为颗粒物沉积的污染物，必须在此指定参数
    /// </summary>
    [Serializable]
    public class SizeDryParticles : ICloneable
    {
        public SizeDryParticles(string Name, double mDIAMETER, double mDEVIATION)
        {
            this.SPECNAM = Name;
            this.DIAMETER = mDIAMETER;
            this.DEVIATION = mDEVIATION;
        }
        /// <summary>
        /// 污染物名称
        /// </summary>
        string m_SPECNAM = "";

        public string SPECNAM
        {
            get { return m_SPECNAM; }
            set { m_SPECNAM = value; }
        }
        /// <summary>
        /// 几何平均直径geometric mass mean diameter
        /// </summary>
        double m_DIAMETER = 0;

        public double DIAMETER
        {
            get { return m_DIAMETER; }
            set { m_DIAMETER = value; }
        }
        /// <summary>
        /// 几何标准偏差eometric standard deviation (microns)
        /// </summary>
        double m_DEVIATION = 0;

        public double DEVIATION
        {
            get { return m_DEVIATION; }
            set { m_DEVIATION = value; }
        }
        private bool m_CalculateSpecies = false;
        /// <summary>
        /// 是否估算污染物
        /// </summary>
        public bool CalculateSpecies
        {
            get { return m_CalculateSpecies; }
            set { m_CalculateSpecies = value; }
        }

        private bool m_IsDryParticles = false;

        /// <summary>
        /// 是否是粒子干沉积，默认为否
        /// </summary>
        public bool IsDryParticles
        {
            get { return m_IsDryParticles; }
            set { m_IsDryParticles = value; }
        }


        public SizeDryParticles ReadFromGroup(string name, string str)
        {
            SizeDryParticles ps = new SizeDryParticles("XX", 1, 1);

            ps.SPECNAM = name;
            ps.DIAMETER = Convert.ToDouble(StrWriter.GetString(str, 1));
            ps.DEVIATION = Convert.ToDouble(StrWriter.GetString(str, 2));

            return ps;
        }
        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }




}
